package com.atguigu.day20.syn01.exer.e4;

public class WindowRunnable implements Runnable {
    int ticket = 2000;

    @Override
    public void run() {

        while (true) {

            if (ticket <= 0) {
                break;
            }
           this. sellTicket();
        }

    }
    //this:
    private synchronized void sellTicket() {
        if(ticket<=0){
            return;
        }
        ticket--;

        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(Thread.currentThread().getName() + "卖了一张票还有[" + ticket + "]张票");
    }
}
